# 列表生成式
print(list(range(1, 9)))
L = []
for i in range(1, 11):
    L.append(i)
print(L)
G = [i * i for i in range(1, 5)]
print(G)
H = [i * i for i in range(1, 5) if i % 2 == 0]
print(H)
print([m + n for m in "ABC" for n in "XYZ"])
L = {'x': 'A', 'y': 'B', 'z': 'C'}
for k, v in L.items():
    print(k, '=', v)
d = {'x': 'A', 'y': 'B', 'z': 'C'}
print([k + "=" + v for k, v in d.items()])
L = ["Hello", "world", "IBM", "Apple"]
print([s.lower() for s in L])
print([x if x % 2 == 0 else -x for x in range(1, 11)])
# 在一个列表生成式中，for前面的if...else是表达式，而for后面的if是过滤条件，不能带else
